package 设计模式.l_责任链模式;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * 教育部
 * 
 * @author caihe
 * @date 2023/3/13 16:01
 */
public class MinistryEducation {
    
    private List<RequestHandler> handlers;
    
    public MinistryEducation() {
        handlers = Arrays.asList(
                new InstructorHandler(), new StudentHandler(), new PrincipalHandler()
        );
    }
    
    public void performRequest(Request request) {
        handlers.stream()
                .sorted(Comparator.comparing(RequestHandler::getPriority))
                .filter(handler -> handler.canHandleRequest(request))
                .forEach(handler -> handler.handle(request));
    }
    
}
